const router = require('koa-router')()

const Database=require('../src/database/database')

database=new Database()

router.prefix('/api')

router.get('/', function (ctx, next) {
    ctx.body = 'this is a users response!'
})

router.get('/bar', function (ctx, next) {
    ctx.body = 'this is a users/bar response'
})


router.get('/json', async (ctx, next) => {
    ctx.body = {
        title: 'koa2 json'
    }
    console.log('api ctx',ctx);
})

router.post('/json',async (ctx,next)=>{
    console.log(ctx.request.body);
    let struct=ctx.requeset
})
router.post('/json-save',async (ctx,next)=>{
    console.log(ctx.request.body);
    let struct=ctx.requeset
    ctx.body = {
        msg: 0
    }
    database.testsave(ctx.request.body).catch(e=>{
        console.log('error',e);})

})
router.post('/json-load',async (ctx,next)=>{
    console.log(ctx.request.body);
    let struct=ctx.requeset.body
    // database.testload(struct)

})
module.exports = router
